package com.usian.model.base;

import com.baomidou.mybatisplus.core.conditions.AbstractLambdaWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.usian.model.common.dtos.PageRequestDto;
import com.usian.model.common.dtos.PageResponseResult;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.common.enums.AppHttpCodeEnum;

public class BaseServiceImpl<M extends BaseMapper<T>,T> extends ServiceImpl<M,T> {
    public ResponseResult paramError=ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
    public ResponseResult okResult=ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    public ResponseResult noData=ResponseResult.okResult(AppHttpCodeEnum.DATA_NOT_EXIST);
    public ResponseResult needLogin=ResponseResult.okResult(AppHttpCodeEnum.NEED_LOGIN);

    public ResponseResult selectFindAll(PageRequestDto dto, IPage page, AbstractLambdaWrapper queryWrapper){
        IPage page1 = page(page, queryWrapper);
        ResponseResult responseResult=new PageResponseResult(dto.getPage(),dto.getSize(),(int)page1.getTotal());
        responseResult.setData(page1.getRecords());
        return responseResult;
    }

    public ResponseResult selectFindAll(PageRequestDto dto, AbstractLambdaWrapper queryWrapper){
        Page page = new Page<>(dto.getPage(), dto.getSize());
        IPage page1 = page(page, queryWrapper);
        ResponseResult responseResult=new PageResponseResult(dto.getPage(),dto.getSize(),(int)page1.getTotal());
        responseResult.setData(page1.getRecords());
        return responseResult;
    }
}
